<template>
  <div class="box_pe">
    <div class="per_box" v-if="maskingLayer">
      <div class="masdilog">
        <h1>AQBMTJ{{"V"+versionNumber}}</h1>
        <div class="mauls">
          <div>
            <img src="../assets/images/logo2.png" class="img">
          </div>
          <div class="ttiles">
            <ul>
              <li>五大安全保密功能：</li>
              <li>违规外联监控、</li>
              <li>身份鉴别、</li>
              <li>外设管控、</li>
              <li>主机审计、</li>
              <li>接入控制</li>
            </ul>
          </div>
        </div>
        <div>
          <button class="submit-btn" @click="maskclikes">开 始</button>
        </div>
        <div>
          <div class="bottils">
            <!-- <p>客户端版本</p>
            <p>{{ versionNumber }}</p> -->
            <p>兴唐通信科技有限公司</p>
            <p style="display: flex;justify-content: center;align-items: center;">{{versionNumber}}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="login" v-if="!maskingLayer">
      <div class="form-structor">
        <div class="signup">
          <!-- <img src="../assets/images/logo.png" class="img"> -->
          <h2>{{ systemName }}</h2>
          <div class="form-holder">
            <input type="text" v-model="formInline.user" class="input" placeholder="请输入账号" />
            <input type="password" v-model="formInline.password" class="input" placeholder="请输入密码" />
          </div>
          <button class="submit-btn" @click="login">登 录</button>
        </div>
      </div>
      <div class="mindus">
        <span class="el-icon-minus" @click="minimizeWin"></span>
      </div>
      <div class="box_bottom" style="z-index: 999;">
        <div style="float:left; margin-left:10px;font-family: 微软雅黑;">客户端版本 {{ versionNumber }}</div>
        <div style="float:right;margin-right:10px;font-family: 微软雅黑;"> {{ temModename }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { menuDatasSINGLE, menuDatasONLINE } from "@/assets/js/menudata";
import { mergedData } from "@/assets/js/userInfo";
export default {
  name: "login",
  data() {
    return {
      aqtjV: window.versions,
      sjsV: window.Cversions,
      systemName: window.systemName,
      dialdengl: true,
      formInline: {
        user: "",
        password: "",
      },
      rules: {},
      menuDatasSINGLE: menuDatasSINGLE,
      menuDatasONLINE: menuDatasONLINE,
      menuList: [],
      systemMode: window.systemMode,
      temModename: window.systemMode == "SINGLE" ? "单机版" : "网络版",
      infoForm: {
        pcName: "",
        AssetNo: "",
        os: "",
        cpuModel: "",
        mac: "",
        ip: "",
        UnitName: "23",
        DeptName: "",
        DeptID: "",
        UnitID: "",
        EmpName: "",
        EmpID: "1",
        SecLvl: "1",
        Machine: "",
        HostType: "1", //0-网络版在线注册 1-单机版 2-网络版离线注册
        accountList: "",
      },
      sjitrmes: "",
      maskingLayer: true,
      versionNumber:"",
    };
  },
  created() {
    var that = this;
    document.onkeydown = function (e) {
      var key = window.event.keyCode;
      if (that.$route.name === "login") {
        if (key == 13) {
          that.login();
        }
      }
    };
    this.$get("/api/v1/getversion").then(res => {
      console.log(res.data)
      this.versionNumber = res.data.version
    })
    this.getForm();
    var myDate = new Date();
    let nian = myDate.getFullYear();
    let yuef = "";
    let rizi = "";
    let shi = myDate.getHours();
    let fen = myDate.getMinutes();
    let maio = myDate.getSeconds();
    if (myDate.getMonth() + 1 >= 10) {
      yuef = myDate.getMonth() + 1;
    } else {
      yuef = "0" + (myDate.getMonth() + 1);
    }
    if (myDate.getDate() >= 10) {
      rizi = myDate.getDate();
    } else {
      rizi = "0" + myDate.getDate();
    }
    this.sjitrmes =
      nian +
      "-" +
      yuef +
      "-" +
      rizi +
      " " +
      (shi < 10 ? "0" + shi : shi) +
      ":" +
      (fen < 10 ? "0" + fen : fen) +
      ":" +
      (maio < 10 ? "0" + maio : maio);
  },
  methods: {
    maskclikes() {
      this.maskingLayer = false
    },
    handleCldeng(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => { });
    },
    okclisqs() {
      console.log(window.username);
      if (
        this.formInline.user == window.username &&
        this.formInline.password == window.password
      ) {
        this.dialdengl = false;
        this.$router.push("/home");
        window.sessionStorage.setItem("userName", this.formInline.user);
      } else {
        this.$message({
          message: "账号或密码不正确，请重新输入",
          type: "warning",
        });
        this.formInline = {};
      }
    },
    login() {
      let userNameValue = this.formInline.user;
      let pinValue = this.formInline.password;
      if (userNameValue === "") {
        this.$message({
          message: "用户名不能为空！",
          type: "warning",
        });
        return false;
      }
      if (pinValue === "") {
        this.$message({
          message: "口令不能为空！",
          type: "warning",
        });
        return false;
      }
      if (systemMode == "SINGLE") {
        if (!menuDatasSINGLE[userNameValue]) {
          this.$message({
            message: "暂无权限！",
            type: "warning",
          });
          return false;
        }
      } else {
        if (!menuDatasONLINE[userNameValue]) {
          this.$message({
            message: "暂无权限！",
            type: "warning",
          });
          return false;
        }
      }

      //使用前端菜单,采用前端的menuData.js的数据构造动态路由和菜单
      if (pinValue !== window.password) {
        this.$message.error("密码错误！");
        return;
      }
      window.sessionStorage.setItem("userName", userNameValue);
      let adminObj = JSON.parse(
        window.localStorage.getItem("administratorLog")
      );
      console.log(adminObj);
      if (adminObj) {
        console.log(this.infoForm);
        adminObj.push({
          LoginUser: userNameValue,
          EmpName: this.infoForm.EmpName,
          DeptName: this.infoForm.DeptName,
          IP: this.infoForm.ip,
          OpTime: this.sjitrmes,
          Content: "登录",
        });
        window.localStorage.setItem(
          "administratorLog",
          JSON.stringify(adminObj)
        );
      } else {
        let adminObj = [];
        adminObj.push({
          LoginUser: userNameValue,
          EmpName: this.infoForm.EmpName,
          DeptName: this.infoForm.DeptName,
          IP: this.infoForm.ip,
          OpTime: this.sjitrmes,
          Content: "登录",
        });
        window.localStorage.setItem(
          "administratorLog",
          JSON.stringify(adminObj)
        );
      }
      // console.log(systemMode);
      if (systemMode == "SINGLE") {
        this.menuList = this.menuDatasSINGLE[userNameValue];
      } else {
        this.menuList = this.menuDatasONLINE[userNameValue];
      }
      console.log(this.menuList, "menuList");
      let routerds;
      routerds = mergedData(this.menuList); //变量循环路由
      let routers = Array.from(new Set(routerds.children)); //去重
      routerds.children = routers;
      // console.log(routers, routerds);
      this.$router.options.routes.push(routerds);
      this.$router.addRoute(routerds); //添加动态路由
      // this.$router.addRoutes(new Array(routerds));  //addRoutes 已弃用
      this.$router.push("/home");
      // window.electron.ipcRenderer.send("windowHome");
    },
    quxiaos() {
      this.formInline = {};
    },
    // 主进程发送缩小
    minimizeWin() {
      window.electron.ipcRenderer.send("window-min");
    },
    getForm() {
      this.$get("/vgmp/config/gethostinfo").then((res) => {
        let { data } = res.data;
        this.infoForm = {
          DeptID: data.deptId,
          DeptName: data.deptName,
          UnitID: data.unitId,
          EmpName: data.empName,
          SecLvl: data.secLevel,
          Machine: data.machine,
          AssetNo: data.assetNum,
          AddressInfo: data.addressInfo,
          HostType: data.hostType, //0-网络版在线注册 1-单机版 2-网络版离线注册
          EmpID: data.empId,
          UnitName: data.unitName,
          licenseModel: data.licenseModel,
          os: data.os,
          pcName: data.pcName,
          cpuModel: data.cpuModel,
          ip: data.ip,
          mac: data.mac,
        };
        let val = "";
        data.accountList.forEach((item) => {
          val += item.accountInfo.account + ",";
        });
        this.infoForm.accountList = val.slice(0, val.lastIndexOf(","));
      });
    },
  },
};
</script>

<style scoped>
.box_pe {
  width: 100%;
  height: 100%;
}

.per_box {
  width: 100%;
  height: 100%;
}

.masdilog {
  display: flex;
  flex-direction: column;
}

.masdilog h1 {
  font-size: 52px;
  color: #484848;
  margin: 26px auto;
  /* padding-left: 112px; */
}

.mauls {
  display: flex;
  /* justify-content: space-around; */
  margin: 8% 0 0 0;
  height: 280px;
}

.mauls .img {
  width: 168px;
  height: 154px;
  margin: 0 104px 0 112px;
}

.mauls .ttiles ul {
  width: 416px;
  font-size: 26px;
  /* line-height: 40px; */
  display: flex;
  flex-wrap: wrap;
}

.mauls .ttiles ul li {
  padding: 2px 0px;
}

.bottils {
  height: 84px;
  float: right;
  font-size: 24px;
  padding: 25px 10px 0 0;
  font-family: 微软雅黑;
}

.masdilog .submit-btn {
  border: 1px solid #000;
  display: block;
  margin: 0 auto;
  width: 308px;
  height: 77px;
  font-size: 52px;
  cursor: pointer;
  opacity: 1;
  text-align: center;
  visibility: visible;
  -webkit-transition: all 0.3s ease;
}

.login {
  overflow: hidden;
  background-color: white;
  /* padding: 40px 30px 30px 30px; */
  /* border-radius: 10px; */
  position: relative;
  /* top: 50%;
  left: 50%;
  width: 400px; */
  width: 100%;
  height: 100vh;
  /* transform: translate(-50%, -50%); */
  transition: transform 300ms, box-shadow 300ms;
  box-shadow: 5px 10px 10px rgba(2, 128, 144, 0.2);
}

.login::before,
.login::after {
  content: "";
  position: absolute;
  width: 700px;
  height: 700px;
  border-top-left-radius: 40%;
  border-top-right-radius: 45%;
  border-bottom-left-radius: 35%;
  border-bottom-right-radius: 40%;
  z-index: 10;
}

.login::after {
  width: 900px;
  height: 900px;
}

.login::before {
  right: -35%;
  top: -85%;
  background-color: #44b979;
  animation: wawes 6s infinite linear;
}

.login::after {
  left: -50%;
  bottom: -115%;
  background-color: #44b979;
  animation: wawes 7s infinite;
}

@keyframes wawes {
  from {
    transform: rotate(0);
  }

  to {
    transform: rotate(360deg);
  }
}

.bnesuts {
  width: 70%;
  height: 50%;
  border-radius: 15px;
  float: left;
  margin-top: 15%;
  margin-left: 15%;
  background-image: url(../assets/images/2.jpg);
}

.dengshus {
  width: 50%;
  height: 80%;
  float: right;
  display: flex;
  flex-direction: column;
  margin-top: 5%;
  /* background: #4581b5; */
  /* border-radius: 14px;
  box-shadow: 0px 0px 10px 6px rgba(0, 0, 0, 0.1);
  opacity: 1; */
  /* align-items: center; */
}

h2 {
  margin-left: 45px;
  margin-bottom: 14px;
  margin-top: 2%;
  font-size: 25px;
  color: #484848;
  /* color: #fff; */
}

.img {
  float: left;
  width: 40px;
}

.box_logins {
  width: 100%;
  height: 100%;
  /* background: #DF0712; */
  /* background-image: linear-gradient(-245deg, transparent 15%, #44B979 50%, #32A666 100%); */
}

:deep(.el-form-item__content) {
  width: 68%;
}

:deep(.el-dialog) {
  height: 100%;
  margin-top: 0 !important;
  margin: 0 auto;
}

:deep(.el-form) {
  display: flex;
  flex-direction: column;
}

.dialog-footer {
  margin-left: 90px;
  /* float: right; */
}

.demo-ruleForm {
  margin-bottom: 10px;
}

.form-structor {
  background-color: #222;
  border-radius: 15px;
  height: 350px;
  width: 425px;
  position: relative;
  overflow: hidden;
  left: 30%;
  top: 20%;
}

.form-structor::after {
  content: "";
  opacity: 0.8;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-repeat: no-repeat;
  background-position: left bottom;
  background-size: 500px;
  background-color: #44b979;
  background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
  background-image: linear-gradient(to right, #43e97b 0%, #38f9d7 100%);
}

.form-structor .signup {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  width: 65%;
  z-index: 5;
  -webkit-transition: all 0.3s ease;
}

.form-structor .signup.slide-up .form-title span {
  margin-right: 5px;
  opacity: 1;
  visibility: visible;
  -webkit-transition: all 0.3s ease;
}

.form-structor .signup .form-title {
  color: #fff;
  font-size: 1.7em;
  text-align: center;
}

.form-structor .signup .form-title span {
  color: rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  -webkit-transition: all 0.3s ease;
}

.form-structor .signup .form-holder {
  border-radius: 15px;
  background-color: #fff;
  overflow: hidden;
  margin-top: 50px;
  opacity: 1;
  visibility: visible;
  -webkit-transition: all 0.3s ease;
}

.form-structor .signup .form-holder .input {
  border: 0;
  outline: none;
  box-shadow: none;
  display: block;
  height: 30px;
  line-height: 30px;
  padding: 8px 15px;
  border-bottom: 1px solid #eee;
  width: 100%;
  font-size: 12px;
}

.form-structor .signup .form-holder .input:last-child {
  border-bottom: 0;
}

.form-structor .signup .form-holder .input::-webkit-input-placeholder {
  color: rgba(0, 0, 0, 0.4);
}

.form-structor .signup .submit-btn {
  background-color: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: 0;
  border-radius: 15px;
  display: block;
  margin: 15px auto;
  padding: 15px 45px;
  width: 100%;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  opacity: 1;
  visibility: visible;
  -webkit-transition: all 0.3s ease;
}

.form-structor .signup .submit-btn:hover {
  transition: all 0.3s ease;
  background-color: rgba(0, 0, 0, 0.6);
}

.mindus {
  position: absolute;
  top: 2px;
  right: 8px;
  z-index: 999;
  cursor: pointer;
  font-size: 22px;
  color: #fff;
}
</style>